'''
Created on May 9, 2012
TC ID: Ecom_5040
Desc: Kiem thu chuc nang sua thong tin don vi bai hoc
@author: Vu Dao
'''
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.contentFunc import clickOnUpdateUnit
from Functions.lessonInformationFunc import clickOnLesson, clickOnContentButton
from Functions.contentFunc import addContent,\
    clickOnSubmitButton, verifyAddContentSuccessfully

username=readData("username",index=2)
password=readData("password",index=2)
tm_lesson=readData("lessonName",index=3)
tm_contentName=readData("contentName",index=2)
tm_content=readData("contentLesson",index=3)
tm_content_=readData("contentLesson")
class Ecom_5040(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5040(self):
        print "Buoc 1: Dang nhap website"
        login(self,username,password)
        
        print "Buoc 2: Click vao bai hoc"
        clickOnLesson(self,tm_lesson)
        
        print "Buoc 3: Click vao Content"
        clickOnContentButton(self)
        
        print "Buoc 4: Click vao Update Unit"
        clickOnUpdateUnit(self)
        
        print "Buoc 5: Thay doi thong tin cho don vi bai hoc"
#        addContent(self,tm_subUnitName,tm_subUnitContent,tm_contentName,edit="Yes")
        addContent(self,tm_contentName,tm_content,edit="Yes")
        
        print "Buoc 6: Click  vao nut Save" 
        clickOnSubmitButton(self)
        
        print "Buoc 7: Kiem tra sua mot don vi bai hoc con thanh cong chay chua??"
        self.assertTrue(verifyAddContentSuccessfully(self,tm_content_,tm_contentName), "Failed: sua mot don vi bai hoc con chua thanh cong")
        print "Sua mot don vi bai hoc con thanh cong"
    
    def tearDown(self):
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5040)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin don vi bai hoc'
                    )
    runner.run(suite)